package com.chase.champagne.utils

fun formatDate(year: Int, month: Int, day: Int): String {
    return StringBuffer("$year-").formatAppend(month, 10).append("-").formatAppend(day, 10).toString()
}

private fun StringBuffer.formatAppend(data: Int, threshold: Int): StringBuffer {
    if (data < threshold) {
        this.append("0$data")
    } else this.append("$data")
    return this
}

fun formatTime(hour: Int, minute: Int, second: Int = -1): String {
    val sb = StringBuffer()
    sb.formatAppend(hour, 10).append(":").formatAppend(minute, 10)
    if (second >= 0) {
        sb.append(":").formatAppend(second, 10)
    }
    return sb.toString()
}